﻿using Autodesk.Revit.UI;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace RevitProject.Helper
{
    public static class RevitContextHelper
    {
        private static ExternalEvent _externalEvent;
        private static Action<UIApplication> _currentAction;
        private static bool _initialized;

        public static void Initialize(UIApplication uiApp)
        {
            if (_initialized)
                return;

            var handler = new RevitExternalEventHandler(app => _currentAction?.Invoke(app));
            _externalEvent = ExternalEvent.Create(handler);
            _initialized = true;
        }

        public static void Execute(Action<UIApplication> action)
        {
            if (!_initialized)
                throw new InvalidOperationException("RevitContextHelper not initialized");

            _currentAction = action;
            _externalEvent.Raise();
        }
    }
}
